package com.yuanfengerp.SalesOrder.service.impl;

import com.yuanfengerp.SalesOrder.dao.ISalesOrderDao;
import com.yuanfengerp.SalesOrder.model.SalesOrder;
import com.yuanfengerp.SalesOrder.service.ISalesOrderService;
import com.yuanfengerp.basicInfoManage.customerInfo.model.Customerinfo;
import com.yuanfengerp.basicInfoManage.warehouseinfo.model.Warehouseinfo;
import com.yuanfengerp.publicUtil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SalesOrderServiceImpl implements ISalesOrderService {
    @Autowired
    private ISalesOrderDao salesOrderDao;
    @Override
    public ArrayList<Warehouseinfo> getWarehouseList() {
        return salesOrderDao.getWarehouseList();
    }

    @Override
    public Warehouseinfo getWarehouse(String warehouse_ID, String warehouse_name) {
        Warehouseinfo warehouseinfo = salesOrderDao.getWarehouse(warehouse_ID, warehouse_name);
        return warehouseinfo;
    }

    @Override
    public ArrayList<Customerinfo> getCustomerList() {
        return salesOrderDao.getCustomerList();
    }

    @Override
    public Customerinfo getCustomer(String customer_ID, String customer_name) {
        return salesOrderDao.getCustomer(customer_ID, customer_name);
    }
    @Override
    public ArrayList<SalesOrder> getSalesOrderList(int pageSize, int offset) {
        return salesOrderDao.getSalesOrderList(pageSize, offset);
    }

    @Override
    public ArrayList<SalesOrder> getSalesOrder(String prod_id, String warehouse_ID, String customer_id) {
        return salesOrderDao.getSalesOrder(prod_id, warehouse_ID, customer_id);
    }

    @Override
    public Result<SalesOrder> insertSalesOrder(SalesOrder salesOrder) {
        int i = salesOrderDao.insertSalesOrder(salesOrder);
        if(i == 1){
            return Result.success();
        }else{
            return Result.failure(400,"添加失败");
        }
    }

    @Override
    public String updateStatus(int status) {
        if(status == 1)
            return "审核通过";
        if(status == 2)
            return "审核拒绝";
        return "待审核";
    }

    @Override
    public Result<SalesOrder> deleteSalesOrder(List<String> prod_id) {
        int i = salesOrderDao.deleteSalesOrder(prod_id);
        return i > 0 ? Result.success() : Result.failure(400,"删除失败");
    }

}
